package com.worldcup.tools;

import com.duwan.commons.csv.CsvUtils;
import com.google.common.collect.Lists;
import com.worldcup.model.question.QuestionMatchResult;
import com.worldcup.service.question.QuestionMatchResultService;
import com.worldcup.service.question.impl.QuestionUserAnswerService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author duwan.zq
 * @date 2019/03/15
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class QuestionMatchAddTool {

    @Autowired
    private QuestionUserAnswerService userAnswerService;

    @Autowired
    private QuestionMatchResultService matchResultService;

    @Test
    public void questionMatchAdd() throws IOException {
        List<String> openIds = userAnswerService.getAllUser();

        List<List<String>> dataList = new ArrayList<>();
        for(int i = 0; i < openIds.size(); i++){
            for(int j = i + 1; j < openIds.size(); j++){
                String openid = openIds.get(i);
                String passiveOpenid = openIds.get(j);
                QuestionMatchResult matchResult = matchResultService.getMatchResult(openid, passiveOpenid);
                QuestionMatchResult passiveMatchResult = matchResultService.getMatchResult(passiveOpenid, openid);
                BigDecimal allScore = matchResult.getHarmonyScore().add(matchResult.getTopicScore());
                BigDecimal passiveAllScore = passiveMatchResult.getHarmonyScore().add(passiveMatchResult.getTopicScore());
                dataList.add(Lists.newArrayList(openid, passiveOpenid, allScore.toString(), passiveAllScore.toString()));
            }
        }
        System.out.println(dataList.size());

        CsvUtils.createCsv(new String[]{"姓名", "朋友", "总分", "反过来的总分"}, dataList, "/Users/zhangqiang/temp/matchResult.csv");
    }
}
